﻿using System;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace HashFoo.Rest.CommonTests
{
    public static class TestUtil
    {
        public static void WaitFor(Action<EventWaitHandle> op, TimeSpan? timeout = null)
        {
            timeout = timeout ?? TimeSpan.FromSeconds(10);
            var syncLock = new ManualResetEvent(false);

            op(syncLock);

            if (syncLock.WaitOne(timeout.Value) == false) Assert.Fail("signal not called");
        }
    }
}